﻿/*
%include "/projects/data_commons/lbd_code/lbd_0_m_lbd_basic.sas" /source2;

Prepared by Feng Lin.

Macro for basic cleaning that fixes firmnum and geo info. Adapted from readlbd1.sas prepared by Chang-Tai Hsieh.

Parameters:
* pdt_in: input data
* pdt_out: output data
* p_exna: whether to exclude observations with missing firmnum, worker, etc.
*/

%macro m_lbd_basic(pdt_in= , pdt_out= , p_exna= );

/* Basic cleaning (See below for some additional information) */


/* REDACTED
Part of the code below updating firmnum variable has been redacted 
*/
data &pdt_out. (drop=yr firmnum refnaics refsic fyear lyear st2 cty2 st cty);
  set &pdt_in.;
  naics = substr(refnaics,1,6)*1;
  sic = substr(refsic,1,4)*1;
  year = yr;
  firmnum3 = firmnum*1;
  *nofirmnum = 0;
  st2 = st*1;
  cty2 = cty*1;
  fips = st2*1000 + cty2;
run;

data &pdt_out. (drop=firmnum3);
  set &pdt_out.;
  firmnum = firmnum3;
run;

%if "&p_exna." = "1" %then %do;

%put Exclude NAs.;


data &pdt_out.;
  set &pdt_out.;
  if firmnum = . then delete;
  if worker = . then delete;
  if worker = 0 then delete;
  if year = . then delete;
run;

%end;

%mend;

/* REDACTED
Comment related to construction of certain variables has been deleted 
*/

/* End of SAS file */
